home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / spoc88 / factrl / factorl.c < prev   
Text File  |  1988-06-21  |  545b  |  31 lines

  1. /* FACTORL.C: Computes factorial of a keyed number */
  2. /* Repeats until user enters 0 */
  3.  
  4. #include <stdio.h>
  5.  
  6. main ()
  7. {
  8. int  value, atoi();
  9. long fact();
  10. char input [6];
  11.  
  12.   do {
  13.     printf ("\nValue? ");
  14.     gets (input);
  15.     value = atoi (input);
  16.     if (value > 0)
  17.       printf ("\nFactorial = %ld\n", fact (value));
  18.     else
  19.       puts ("\nCannot take factorial of negative number\n");
  20.   } while (value);
  21. }
  22.  
  23. long fact (int val)
  24. {
  25. long result = 0;
  26.  
  27.   if (val)
  28.     result = val * fact (val-1);
  29.   return (result);
  30. }
  31.